<template>
	<view class="layout pageBg">
		<common-titile title="推荐"></common-titile>

		<view class="banner">
			<swiper indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff" autoplay
				circular duration="500" interval="3000">
				<swiper-item v-for="item in bannerList" :key="item._id">
					<view>
						<image class="banner-image" :src="item.picurl.url" mode="aspectFill"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>

		<view class="box">
			<view class="top">
				<view class="title">猜你喜欢</view>
				<view class="right">
					<uni-icons type="calendar" size="30"></uni-icons>
					<view class="day">
						<uni-dateformat :date="new Date()" format="dd日"></uni-dateformat>
					</view>
				</view>
			</view>
			<view class="content">
				<scroll-view scroll-x>
					<view class="image" v-for="item in guessYouLike" :key="item._id" @click="goDetail(item._id)">
						<image :src="item.picurl.url" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>

		<view class="box">
			<view class="top">
				<view class="title">精选主题</view>
			</view>
			<view class="content">
				<view class="theme">
					<navigator :url="'/pages/classList/classList?id=' + item._id + '&name=' + item.name" class="item"
						v-for="item in classfiyList" :key="item._id">
						<common-classfiy :data="item"></common-classfiy>
					</navigator>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		getBanner
	} from "@/api/banner.js"
	import {
		getWallpaper
	} from "@/api/wallpaper.js"
	import {
		getClassfiy
	} from "@/api/classfiy.js"
	import {
		onShareAppMessage,
		onShareTimeline
	} from '@dcloudio/uni-app';

	const classfiyList = ref([])
	const bannerList = ref([])
	const guessYouLike = ref([])

	const getClassfiyList = async () => {
		const {
			data
		} = await getClassfiy()
		classfiyList.value = data
	}
	const getBannerList = async () => {
		const {
			data
		} = await getBanner()
		bannerList.value = data
	}

	const getWallpaperList = async () => {
		const {
			data
		} = await getWallpaper()
		guessYouLike.value = data
	}

	//跳转到预览界面
	const goDetail = (id) => {
		uni.setStorageSync("storgClassList", guessYouLike.value)
		uni.navigateTo({
			url: "/pages/detail/detail?id=" + id
		})
	}

	//分享给好友
	onShareAppMessage(() => {
		return {
			title: "噜啦壁纸",
			path: "/pages/index/index"
		}
	})

	//分享到朋友圈
	onShareTimeline(() => {
		return {
			title: "噜啦壁纸"
		}
	})

	getBannerList()
	getWallpaperList()
	getClassfiyList()
</script>

<style lang="scss" scoped>
	.layout {

		.banner {
			width: 750rpx;
			padding: 30rpx 0;
			margin-top: 80rpx;

			swiper {
				width: 750rpx;
				height: 340rpx;

				swiper-item {
					width: 100%;
					height: 100%;
					display: flex;
					justify-content: center;
					align-items: center;
					padding: 0;
					border-radius: 15rpx;

					.link {
						width: 100%;
						height: 100%;

						.banner-image {
							width: 100%;
							height: 100%;
							border-radius: 15rpx;
						}
					}
				}
			}
		}

		.box {
			padding: 20rpx;

			.top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 35rpx;

				.title {
					font-weight: bold;
				}

				.right {
					display: flex;
					align-items: center;
				}
			}

			.content {
				width: 720rpx;
				margin-top: 30rpx;

				scroll-view {
					white-space: nowrap;

					.image {
						width: 200rpx;
						height: 430rpx;
						display: inline-block;
						margin-right: 15rpx;

						image {
							width: 100%;
							height: 100%;
							border-radius: 15rpx;
						}
					}

					.image:last-child {
						margin-right: 10rpx;
					}
				}

				.theme {
					display: grid;
					grid-template-columns: repeat(3, 1fr);
					gap: 15rpx;
					margin: 0 10rpx;

					.item {
						position: relative; // 设置为相对定位
					}
				}
			}
		}
	}
</style>